package com.sf.fy.uav.applet.order.controller;

import com.sf.fy.uav.common.request.order.AnswerFeedbackRequest;
import com.sf.fy.uav.common.request.order.CloseFeedbackRequest;
import com.sf.fy.uav.common.request.order.SysFeedbackRequest;
import com.sf.fy.uav.common.response.order.SysFeedbackResponse;
import com.sf.fy.uav.common.utils.Rs;
import com.sf.fy.uav.order.controller.FeedbackRest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * @author LTQ
 */
@RestController
@RequestMapping("/home/feedback/")
public class SysFeedbackController {

    @Autowired
    private FeedbackRest feedbackRest;


    @GetMapping("get-feedback")
    @CrossOrigin
    public Rs<List<SysFeedbackResponse>> getFeedbacks(@RequestParam Integer page, @RequestParam Integer size, @RequestParam(required = false) String orderId,
                                                      @RequestParam(required = false) String workOrderNum, @RequestParam(required = false) Integer status, @RequestParam(required = false) String feedbackTypeName,
                                                      @RequestParam(required = false) Integer platformCode) {
        SysFeedbackRequest sysFeedbackRequest = new SysFeedbackRequest();
        sysFeedbackRequest.setPage(page);
        sysFeedbackRequest.setSize(size);
        sysFeedbackRequest.setFeedbackTypeName(feedbackTypeName);
        sysFeedbackRequest.setStatus(status);
        sysFeedbackRequest.setWorkOrderNum(workOrderNum);
        sysFeedbackRequest.setOrderId(orderId);
        sysFeedbackRequest.setPlatformCode(platformCode);
        return Rs.success(feedbackRest.getFeedbacks(sysFeedbackRequest));
    }

    @GetMapping("get-total")
    @CrossOrigin
    public Rs<Long> getTotal(@RequestParam(required = false) String orderId,
                             @RequestParam(required = false) String workOrderNum, @RequestParam(required = false) Integer status, @RequestParam(required = false) String feedbackTypeName,
                             @RequestParam(required = false) Integer platformCode) {
        return Rs.success(feedbackRest.getTotal(orderId, workOrderNum, status, feedbackTypeName, platformCode));
    }

    @PostMapping("reply")
    @CrossOrigin
    public Rs<Void> reply(@RequestBody AnswerFeedbackRequest answerFeedbackRequest) {
        feedbackRest.answer(answerFeedbackRequest);
        return Rs.success();
    }

    @PostMapping("close")
    @CrossOrigin
    public Rs<Void> close(@RequestBody CloseFeedbackRequest closeFeedbackRequest) {
        feedbackRest.close(closeFeedbackRequest);
        return Rs.success();
    }
}
